package com.interview.javabase.tcpupd;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author: zsg
 * @description:
 * @date: 2019/6/8 20:59
 * @modified:
 */
public class SocketServer {
    public static void main(String[] args) {
        try {
            ServerSocket serverSocket = new ServerSocket(60000);
            while (true){
                Socket accept = serverSocket.accept();
                InputStream inputStream = accept.getInputStream();

               byte[] bytes = new byte[1024];
                int read = inputStream.read(bytes);
                String s = new String(bytes, 0, read);
                System.out.println(s);
                System.out.print(s.length());
                OutputStream outputStream = accept.getOutputStream();
                outputStream.write(String.valueOf(s.length()).getBytes());
                inputStream.close();
                outputStream.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
